//
//  WZVisitor.m
//  weibo
//
//  Created by mac on 16/2/25.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "WZVisitor.h"
#import "PureLayout.h"

@interface WZVisitor ()

@property(nonatomic,strong)UIImageView *animateImageView;
@property(nonatomic,strong)UIImageView *iconImageView;
@property(nonatomic,strong)UIImageView *maserImageView;

@property(nonatomic,strong)UILabel *detailLable;
@property(nonatomic,strong)UIButton *registButton;
@property(nonatomic,strong)UIButton *loginButton;

@end

@implementation WZVisitor

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    
    return self;
}


-(UIImageView *)animateImageView{
    if (_animateImageView == nil) {
        _animateImageView = [[UIImageView alloc] init];
        _animateImageView.image = [UIImage imageNamed:@"visitordiscover_feed_image_smallicon"];
        [_animateImageView sizeToFit];
        [self addSubview:_animateImageView];
        
    }
    return _animateImageView;
}
-(UIImageView *)iconImageView{
    if (_iconImageView == nil) {
        _iconImageView = [[UIImageView alloc] init];
        _iconImageView.image = [UIImage imageNamed:@"visitordiscover_feed_image_house"];
        [_iconImageView sizeToFit];
        [self addSubview:_iconImageView];
        
    }
    return _iconImageView;
}
-(UIImageView *)maserImageView{
    if (_maserImageView == nil) {
        _maserImageView = [[UIImageView alloc] init];
        _maserImageView.image = [UIImage imageNamed:@"visitordiscover_feed_mask_smallicon"];
        [_maserImageView sizeToFit];
        [self addSubview:_maserImageView];
        
    }
    return _maserImageView;
}
-(UILabel *)detailLable{
    
    if (_detailLable == nil) {
        _detailLable = [[UILabel alloc] init];
        _detailLable.text = @"喀什的空间撒谎大会上大三的";
        _detailLable.textAlignment = NSTextAlignmentCenter;
        _detailLable.font = [UIFont systemFontOfSize:14];
        [self addSubview:_detailLable];
    }
    return _detailLable;
}
-(UIButton *)registButton{
    if (_registButton == nil) {
        _registButton = [[UIButton alloc] init];
        
        [_registButton setBackgroundImage:[UIImage imageNamed:@"common_button_white_disable"] forState:UIControlStateNormal];
        [_registButton setTitle:@"注册" forState:UIControlStateNormal];
        [_registButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
        [_registButton addTarget:self action:@selector(registerClick) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_registButton];
    }
    return _registButton;
}
-(void)registerClick{
    if ([self.delegate respondsToSelector:@selector(registe)]) {
        [self.delegate registe];
    }
    
}
-(UIButton *)loginButton{
    if (_loginButton == nil) {
        _loginButton = [[UIButton alloc] init];
        
        [_loginButton setBackgroundImage:[UIImage imageNamed:@"common_button_white_disable"] forState:UIControlStateNormal];
        [_loginButton setTitle:@"登录" forState:UIControlStateNormal];
        [_loginButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
        [_loginButton addTarget:self action:@selector(loginClick) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_loginButton];
    }
    return _loginButton;
}
-(void)loginClick{
    if ([self.delegate respondsToSelector:@selector(login)]) {
        [self.delegate login];
    }
}
-(void)setAnimation{
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    animation.toValue = @(M_PI_4*2);
    
    animation.duration = 5;
    animation.repeatCount = MAXFLOAT;
    animation.removedOnCompletion = false;
    
    [self.animateImageView.layer addAnimation:animation forKey:nil];
}

-(void)setVisitorAttributeWithImageName:(NSString *)imageName andDetailLable:(NSString *)detailLable andHasAnimation:(BOOL) hasAnimation{
    [self.iconImageView setImage:[UIImage imageNamed:imageName]];
    self.detailLable.text = detailLable;
    if (hasAnimation) {
        self.animateImageView.hidden = NO;
    }else{
        self.animateImageView.hidden = YES;
    }
}

-(void)layoutSubviews{
    [super layoutSubviews];
    
    [self.animateImageView autoSetDimensionsToSize:self.animateImageView.image.size];
    [self.animateImageView autoCenterInSuperview];

    [self.maserImageView autoSetDimensionsToSize:self.maserImageView.image.size];
    [self.maserImageView autoCenterInSuperview];
   
    
    
    [self.iconImageView autoSetDimensionsToSize:self.iconImageView.image.size];
    [self.iconImageView autoCenterInSuperview];


    [self.detailLable autoSetDimensionsToSize:CGSizeMake(216, 30)];
     [self.detailLable autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.animateImageView withOffset:10];
    [self.detailLable autoPinEdge:ALEdgeLeft toEdge:ALEdgeLeft ofView:self withOffset:([UIScreen mainScreen].bounds.size.width*0.5-108)];
 

   
    
    [self.registButton autoSetDimensionsToSize:CGSizeMake(100, 30)];
    [self.registButton autoPinEdge:ALEdgeRight toEdge:ALEdgeRight ofView:self.detailLable];
    [self.registButton autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.detailLable withOffset:10];
    
    
    
    [self.loginButton autoSetDimensionsToSize:CGSizeMake(100, 30)];
    [self.loginButton autoPinEdge:ALEdgeLeft toEdge:ALEdgeLeft ofView:self.detailLable];
    [self.loginButton autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.detailLable withOffset:10];
    
    
    
    
}


@end
